package cn.wolfcode.ssm.web.controller;


import cn.wolfcode.ssm.domain.Exam;
import cn.wolfcode.ssm.service.IExamService;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.qo.JsonResult;
import cn.wolfcode.ssm.util.RequireAnnotation;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private IExamService examService;


    @RequireAnnotation(name = "试卷页面",expression = "exam:list")
    @RequestMapping("/list")
    public String list(Model model,Long id){
        Exam exam = examService.get(id);
        model.addAttribute("exam",exam);
        return "exam/试卷预览页面";
    }


    @RequireAnnotation(name = "试卷页面",expression = "exam:input")
    @RequestMapping("/input")
    public String input(Model model){
        return "exam/新增试卷页面";
    }
    @RequestMapping("/saveOrUpdate")
    @RequireAnnotation(name = "试卷新增/编辑",expression = "exam:saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Exam exam){
        Exam newExam = examService.save(exam);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(newExam);
        return jsonResult;
    }
}
